package com.le.tester.utils;

import org.apache.commons.mail.HtmlEmail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;

/**
 * currentTime:2022/3/21 14:45
 * description:发送邮件工具
 */
public class EmailUtil {
    private static final Logger LOG = LoggerFactory.getLogger(EmailUtil.class);

    //    发送邮件
    public static void sendEmail(String emailFrom, String emailTo, Long type, String title, String hostName) {
        //暂时默认的使用qq邮箱
        try {

            HtmlEmail email = new HtmlEmail();
            email.setHostName(hostName);
            email.setCharset(StandardCharsets.UTF_8.toString());
            email.addTo(emailTo);
            email.setFrom(emailFrom, "李伟彬");
            email.setAuthentication(emailFrom, "ozedmxqlduyobjhh");
            //邮件的标题
            email.setSubject(title);
            //消息的内容
            email.setMsg("123456");
            email.send();
        } catch (Exception e) {
            LOG.info("发送邮件出现异常：{}", e.getMessage());
        }
    }

    public static void main(String[] args) {
        EmailUtil.sendEmail("314022271@qq.com", "1183852727@qq.com", 0L, "test", "smtp.qq.com");
    }

}
